#include "trans.h"
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>

int main (int argc, char* argv[]){
	FILE* fp = file_open("dictionary.txt");
	char* target_name = NULL;
	target_t* target = NULL;
	char* dependency_name = NULL;
	char* line_temp;
	char* line = malloc(100*sizeof(char));
	while((line = file_getline(line, fp)) != NULL) {
		line_temp = strtok(line, "\n"); //Remove newline character at end if there is one
		//Remove leading whitespace
		while (*line_temp == ' ' || *line_temp == '\t')
			line_temp++;
		if (strlen(line_temp) <= 0) //skip if whitespace-only
			continue;
		if (target == NULL)
		{
			//Not currently inside a target, look for a new one
			target_name = strtok(line_temp, ":");
			if (target_name != NULL && strlen(target_name) > 0)
			{
				target = add_target(target_name);
				dependency_name = strtok(NULL, " ");
				while (dependency_name != NULL)
				{
					target->dependency_head = list_add(target->dependency_head, dependency_name);
					dependency_name = strtok(NULL, " ");
				}
			}
		}
		else if (strncmp(line_temp, "end", 3) == 0)
		{
			//End of target's command list
			target = NULL;
			target_name = NULL;
			
		}
		else
		{
			//Add command to list
			target->command_head = list_add(target->command_head, line_temp);
			printf("New word: %s\n", line_temp);
		}
	}
	fclose(fp);
	free(line);
	return 0;
}
	
	
	

